<template>
    <div class="xl-table">
        <xlUntil text="科技项目管理" @addForm="addForm" :queryParam="queryParam" @delBatch="delBatch"
                 @searchKeyWord="searchKeyWord" :searchColumns="columns" :export-xls-data="columns"
                 :export-xls-url="url.exportXlsUrl" :until-visible="false"></xlUntil>
        <div class="xl-table-content">
            <xlTable
                :columns="columns"
                :dataSource="data"
                rowKey="id"
                :pagination="pagination"
                :loading="loading"
                @change="handleTableChange"
                bordered
                :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}">
                >
                <template v-slot:action="scope">
                    <a @click="editForm(scope.record)">编辑</a>
                    <a-divider type="vertical"/>
                    <a-dropdown>
                        <a class="ant-dropdown-link">更多
                            <a-icon type="down"/>
                        </a>
                        <a-menu slot="overlay">
                            <a-menu-item @click="seeForm(scope.record)">
                                <a>查看</a>
                            </a-menu-item>
                            <!-- <a-menu-item @click="matchingCompany(scope.record)" v-if="!scope.record.notHasMatchingCondition">
                                <a>匹配企业</a>
                            </a-menu-item> -->
                            <a-menu-item>
                                <a-popconfirm title="确定删除吗?" @confirm="() => delForm(scope.record.id)">
                                    <a>删除</a>
                                </a-popconfirm>
                            </a-menu-item>
                        </a-menu>
                    </a-dropdown>
                </template>
            </xlTable>
        </div>
        <xlForm ref="xlForm" @handleOk="handleOk"></xlForm>
        <seeForm ref="seeForm"></seeForm>
        <matchResult ref="matchResult"></matchResult>
    </div>
</template>

<script>

import xlForm from './model/form'
import seeForm from './model/seeForm'
import xlMixin from '../../../components/mixin/index'
import matchResult from './model/matchResult'
import {projectMatchingCompany, technologyProjectDetailGet} from "@/assets/api/policy";

export default {
    name: "index",
    mixins: [xlMixin],
    data() {
        return {
            data: [],
            columns: [
                {
                    title: '序号',
                    key: 'rowIndex',
                    align: "center",
                    fixed: 'left',
                    width: '180px',
                    sorter: (a) => a.id,//排序
                    customRender: function (t, r, index) {
                        return parseInt(index) + 1;
                    }
                },
                {
                    title: '编号',
                    dataIndex: 'technologyProjectCode',
                    type: 'input',
                    formVisible: true,
                    tableVisible: true
                },
                {
                    title: '项目名称',
                    dataIndex: 'projectName',
                    type: 'input'
                },
                {
                    title: '所属项目体系',
                    dataIndex: 'projectSystem',
                    type: 'select',
                    typeData: 'POLICY_TECHNOLOGY_PROJECT_SYSTEM'
                },
                {
                    title: '项目开始月份',
                    dataIndex: 'projectStartMonth',
                    type: 'input.number'
                },
                {
                    title: '项目结束月份',
                    dataIndex: 'projectEndMonth',
                    type: 'input.number'
                },
                {
                    title: '申报地址',
                    dataIndex: 'declareUrl',
                    type: 'input',
                    tableVisible: true
                },
                {
                    title: '是否需要推荐函',
                    dataIndex: 'needRecommendation',
                    type: 'radio',
                    tableVisible: true,
                    typeData: [
                        {
                            dataName: '需要',
                            dataValue: 0
                        },
                        {
                            dataName: '不需要',
                            dataValue: 1
                        }
                    ],
                    span: 2
                },
                {
                    title: '发布时间',
                    dataIndex: 'publishDateTime',
                    type: 'dateTime',
                    tableVisible: true
                },
                {
                    title: '负责部门',
                    dataIndex: 'responsibleDepartment',
                    type: 'input',
                    tableVisible: true
                },
                {
                    title: '负责人',
                    dataIndex: 'responsiblePerson',
                    type: 'input',
                    tableVisible: true
                },
                {
                    title: '联系电话',
                    dataIndex: 'contactNumber',
                    type: 'input',
                    tableVisible: true
                },
                {
                    title: '详细介绍',
                    dataIndex: 'detail',
                    type: 'editor',
                    tableVisible: true,
                    span: 2
                },
                {
                    title: '附件',
                    dataIndex: 'policyAttachments',
                    type: 'upload.files',
                    tableVisible: true,
                    span: 2
                },
                {
                    title: '操作',
                    dataIndex: 'action',
                    align: "center",
                    fixed: 'right',
                    width: '150px',
                    scopedSlots: {customRender: 'action'},
                }
            ],
            url: {
                list: "/system/api/technology/project/page/list",
                add: '/system/api/technology/project/save',
                edit: '/system/api/technology/project/save',
                delete: "/system/api/technology/project/remove"
            }
        }
    },
    components: {
        xlForm,
        seeForm,
        matchResult
    },
    created() {
        this.formatMerge()
        this.pageOnload()
    },
    methods: {
        addForm() {
            this.$refs.xlForm.tableTitle = '新增'
            this.$refs.xlForm.confirmLoading = false
            this.$refs.xlForm.formatForm({policyAreaCode: 'PA3',needRecommendation: 1})
            this.$refs.xlForm.type = 1
            this.$refs.xlForm.visible = true
        },
        seeForm(data) {
            technologyProjectDetailGet({
                param: data.technologyProjectCode
            }).then(res => {
                this.$refs.seeForm.formatData(this.columns, res.result)
                this.$refs.seeForm.visible = true
            })

        },
        editForm(data) {
            technologyProjectDetailGet({
                param: data.technologyProjectCode
            }).then(res => {
                this.$refs.xlForm.tableTitle = '修改'
                this.$refs.xlForm.confirmLoading = false
                this.$refs.xlForm.formatForm(res.result)
                this.$refs.xlForm.type = 2
                this.$refs.xlForm.visible = true
            })
        },
        matchingCompany(data) {
            this.matching = true
            projectMatchingCompany({param: data.id}).then(res => {
                this.$refs.matchResult.queryParam = {policyUnscrambleId: data.id}
                this.$refs.matchResult.pageOnload()
                this.matching = false
                this.$refs.matchResult.visible = true
            }).catch(_ => {
                console.log('error')
                this.matching = false
            })
        }
    }
}
</script>

<style scoped lang="less">
.xl-table {
    .xl-table-content {
        padding: 16px;
    }
}
</style>